package com.auxgroup.smarthome.business.vo;

import com.auxgroup.bridge.app.inner.vo.AppUserVo;
import com.auxgroup.smarthome.utils.NewDateUtils;
import org.apache.commons.lang3.StringUtils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author Qiuhua Lai
 * @email qhlai@gizwits.com
 */
public class AppExportTitleVo {
    private String uid;
    private String nickName;
    private String phone;
    private String realName;
    private String createdAt;
    private String gender;

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(String createdAt) {
        this.createdAt = createdAt;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public static AppExportTitleVo createExportData(AppUserVo exportDataVo) {
        AppExportTitleVo export = new AppExportTitleVo();
        export.setUid(exportDataVo.getUid());
        export.setRealName(exportDataVo.getRealName());
        long epoch = exportDataVo.getCreatedAt() == null? 0L : exportDataVo.getCreatedAt();
        LocalDateTime createTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(epoch), NewDateUtils.getBeijingZoneId());
        export.setCreatedAt(createTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));

        String genderStr = "未知";
        if(StringUtils.isNotEmpty(exportDataVo.getGender())) {
            genderStr = exportDataVo.getGender().equals("M")? "男" : exportDataVo.getGender().equals("F")? "女" : "未知";
        }
        export.setGender(genderStr);
        export.setNickName(exportDataVo.getNickName());
        export.setPhone(exportDataVo.getPhone());
        return export;
    }
}
